const db = require('../db/index')
const RunSql = async (sql, val) => {
  return new Promise(resolve => {
    db.query(sql, val, (err, result) => {
      console.log(err);
      if (err) return err;
      resolve(result)
    })
  })
}
exports.getNovalData = async (req, res) => {
  const reqdata = req.body;
  const searchSql = "select * from novalcapater where titleLink=?"
  let result = await RunSql(searchSql, reqdata.titleLink);
  result[0].content = JSON.stringify(result[0].content);
  res.cc('获取成功', 200, result);
}

exports.getCapaterData = async (req, res) => {
  const searchSql = "select titleName,titleLink from novalcapater"
  let result = await RunSql(searchSql);
  res.cc('获取成功', 200, result);
}

exports.getLastReadCapater = async (req, res) => {
  const reqdata = req.body;
  console.log(reqdata);
  const searchSql = "select * from novalcapater where `read`=?"
  let result = await RunSql(searchSql, reqdata.read);
  res.cc('获取成功', 200, result);
}